package agh.sr.lab4.chat.server;

import java.util.HashMap;

import agh.sr.lab4.common.utils.Config;

import Chat.ClientListener;
import Ice.Current;
import Ice.LocalObjectHolder;
import Ice.Object;
import Ice.ServantLocator;
import Ice.UserException;

public class ChatServantLocator implements ServantLocator {

	private HashMap<String, ChatRoomI> roomsMap = new HashMap<String, ChatRoomI>();
	private IChatDataProvider chatDataProvider = new ChatDataProvider();

	@Override
	public synchronized Object locate(Current curr, LocalObjectHolder cookie)
			throws UserException {

		String operation = curr.operation;
		if (operation.equalsIgnoreCase("join")) {
			String roomName = curr.ctx.get(Config.CHAT_ROOM_KEY);
			
			ChatRoomI chatRoom = roomsMap.get(roomName);
			if (chatRoom == null) {
				chatRoom = new ChatRoomI();
			}
			chatRoom.registerListener();

		}

		return null;
	}

	@Override
	public synchronized void finished(Current curr, Object servant,
			java.lang.Object cookie) throws UserException {

	}

	@Override
	public synchronized void deactivate(String category) {

	}

}
